rows = [ {'address': '5412 N CLARK', 'date': '07/01/2012'},
{'address': '5148 N CLARK', 'date': '07/04/2012'},
{'address': '5800 E 58TH', 'date': '07/02/2012'},
{'address': '2122 N CLARK', 'date': '07/03/2012'},
{'address': '5645 N RAVENSWOOD', 'date': '07/02/2012'},
{'address': '1060 W ADDISON', 'date': '07/02/2012'},
{'address': '4801 N BROADWAY', 'date': '07/01/2012'},
{'address': '1039 W GRANVILLE', 'date': '07/04/2012'},
]
from operator import itemgetter
from itertools import groupby
# groupby()函数扫描整个序列,查找相同的元素,每次迭代返回一个值和一个迭代对象(包含全部元素)
# 注意gropupby()只能检查连续的元素,使用前要对序列进行排序
rows.sort(key=itemgetter('date'))
for data, item in groupby(rows,key=itemgetter('date')):
    print(data)
    for i in item:
        print(i)
